package com.gxgeek.eshopinventory.request;

import com.gxgeek.eshopinventory.entity.ProductInventory;
import com.gxgeek.eshopinventory.service.IProductInventoryService;
import lombok.Data;

/**
 * @author gaoxing
 * @create 2018-01-12 下午9:20
 */
@Data
public class ProductInventoryCacheRefreshRequest implements Request {

    /**
     * 商品id
     */
    private Integer productId;
    /**
     * 商品库存Service
     */
    private IProductInventoryService productInventoryService;

    public ProductInventoryCacheRefreshRequest(Integer productId,
                                               IProductInventoryService productInventoryService) {
        this.productId = productId;
        this.productInventoryService = productInventoryService;
    }

    @Override
    public void process() {
        // 从数据库中查询最新的商品库存数量
        ProductInventory productInventory = productInventoryService.findProductInventory(productId);
        // 将最新的商品库存数量，刷新到redis缓存中去
        productInventoryService.setProductInventoryCache(productInventory);
    }

}
